package com.itheima.controller.returnreason;

import com.itheima.api.returnreason.OmsOrderReturnApplyService;
import com.itheima.vo.domain.AjaxResult;
import com.itheima.vo.pojo.OmsOrderReturnApply;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/returnApply")
@Slf4j
public class OmsOrderReturnApplyController {

    @DubboReference
    private OmsOrderReturnApplyService applyService;

    /**
     * 分页查询退货申请
     *
     * @param pageNum
     * @param pageSize
     * @param id
     * @param createTime
     * @param handleMan
     * @param handleTime
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(Integer pageNum, Integer pageSize, Integer id, String createTime,
                           String handleMan, String handleTime) {
        Map map = applyService.findByPage(pageNum, pageSize, id, createTime, handleMan, handleTime);
        return AjaxResult.success(map);
    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestParam List<Integer> ids) {
        applyService.deleteByIds(ids);
        return AjaxResult.success();
    }

    /**
     * 修改退货申请状态
     *
     * @param id
     * @param returnApply
     * @return
     */
    @PostMapping("/update/status/{id}")
    public AjaxResult update(@PathVariable Integer id, @RequestBody OmsOrderReturnApply returnApply) {
        applyService.updateStatus(id, returnApply);
        return AjaxResult.success();
    }

    /**
     * 获取退货申请详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getOne(@PathVariable Integer id) {
        OmsOrderReturnApply omsOrderReturnApply = applyService.getById(id);
        return AjaxResult.success(omsOrderReturnApply);
    }
}
